Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass DeployTarget in SDK #5616

Merged
merged 8 commits into from
Mar 3, 2025
Merged

Pass DeployTarget in SDK #5616

merged 8 commits into from
Mar 3, 2025

Conversation

ffjlabo
Copy link
Member

@ffjlabo ffjlabo commented Mar 3, 2025

What this PR does:

as title

Why we need it:

We need DeployTarget for the Deployment plugin to use platform-specific config.

Which issue(s) this PR fixes:

Part of #5530

Does this PR introduce a user-facing change?:

  • How are users affected by this change:
  • Is this breaking change:
  • How to migrate (if breaking change):

Signed-off-by: Yoshiki Fujikane <[email protected]>
Signed-off-by: Yoshiki Fujikane <[email protected]>
@ffjlabo ffjlabo force-pushed the extract-deploy-targets-in-sdk branch from 0b6ccd7 to fa64fcd Compare March 3, 2025 04:50
Copy link

codecov bot commented Mar 3, 2025

Codecov Report

Attention: Patch coverage is 14.28571% with 24 lines in your changes missing coverage. Please review.

Project coverage is 26.58%. Comparing base (4afa3e6) to head (1efc476).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
pkg/plugin/sdk/deployment.go 0.00% 19 Missing ⚠️
...p/pipedv1/plugin/kubernetes/deployment/rollback.go 0.00% 3 Missing ⚠️
...g/app/pipedv1/plugin/kubernetes/deployment/sync.go 33.33% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #5616   +/-   ##
=======================================
  Coverage   26.58%   26.58%           
=======================================
  Files         474      474           
  Lines       50546    50564   +18     
=======================================
+ Hits        13438    13444    +6     
- Misses      36045    36057   +12     
  Partials     1063     1063           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@Warashi Warashi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you.
I think the spec you're trying to implement is good, and I've commented on how you've implemented it.

Comment on lines 210 to 213
dtNames, err := request.GetInput().GetDeployment().GetDeployTargets(s.commonFields.config.Name)
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to get deploy targets for plugin %s: %v", s.commonFields.config.Name, err)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The plugin which doesn't have deploy target configurations such as WAIT will return an error in this if statement, and it's not expected behavior.

ref;

func (d *Deployment) GetDeployTargets(pluginName string) ([]string, error) {
dps, ok := d.GetDeployTargetsByPlugin()[pluginName]
if !ok || len(dps.GetDeployTargets()) == 0 {
return nil, fmt.Errorf("deploy target not found for plugin %v", pluginName)
}
return dps.GetDeployTargets(), nil
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Warashi
Thanks.
I fixed the method logic to allow the case of no deploy target. We can decide whether it is an error or not in the plugin logic from now.
0e167c0

Comment on lines 217 to 228
if dt := s.commonFields.config.FindDeployTarget(name); dt != nil {
var sdkDt DeployTargetConfig
if err := json.Unmarshal(dt.Config, &sdkDt); err != nil {
return nil, status.Errorf(codes.Internal, "failed to unmarshal deploy target config: %v", err)
}

deployTargets = append(deployTargets, &DeployTarget[DeployTargetConfig]{
Name: name,
Labels: dt.Labels,
Config: sdkDt,
})
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[IMO]
We can use the early-return pattern with the error containing the deployTarget name that is not found when dt == nil .

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed on 8173d91

Copy link
Member

@t-kikuc t-kikuc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, I left some nits.

}

if len(dtNames) != len(deployTargets) {
return nil, status.Errorf(codes.Internal, "the number of deploy targets in the piped plugin config should be the same as the ones set on the deployment")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nits]
Let's add len(dtNames) and len(deployTargets) in the message to make it easier to troubleshoot.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed on fc90b4c


dtNames, err := request.GetInput().GetDeployment().GetDeployTargets(s.commonFields.config.Name)
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to get deploy targets for plugin %s: %v", s.commonFields.config.Name, err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nits]
[nit]
I wanna clarify which one we mention,

  • the deployTraget was not found in a piped config
  • the deployTarget was not set in the request(deployment)
Suggested change
return nil, status.Errorf(codes.Internal, "failed to get deploy targets for plugin %s: %v", s.commonFields.config.Name, err)
return nil, status.Errorf(codes.Internal, "failed to get deploy targets from the deployment for plugin %s: %v", s.commonFields.config.Name, err)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed on fbb133e

Comment on lines 218 to 221
var sdkDt DeployTargetConfig
if err := json.Unmarshal(dt.Config, &sdkDt); err != nil {
return nil, status.Errorf(codes.Internal, "failed to unmarshal deploy target config: %v", err)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[IMO] If possible, it's better to cache DeployTargetConfigs in the server instead of repeating unmarshaling.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@t-kikuc
Thanks, that sounds nice.
I added a TODO comment for it. I think it would be nice to focus on passing the deploy targets in this PR. Is it OK?
03519ad

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! TODO is best for this case!

We don't have to do that now.

ffjlabo added 5 commits March 3, 2025 14:33
Signed-off-by: Yoshiki Fujikane <[email protected]>
Signed-off-by: Yoshiki Fujikane <[email protected]>
Signed-off-by: Yoshiki Fujikane <[email protected]>
Signed-off-by: Yoshiki Fujikane <[email protected]>
…which don't need them

Signed-off-by: Yoshiki Fujikane <[email protected]>
for _, name := range dtNames {
dt := s.commonFields.config.FindDeployTarget(name)
if dt == nil {
continue
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[IMO]
How about returning an error here? If we return here, we can remove the if len(dtNames) != len(deployTargets) block after the for loop.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Warashi
Ah, finally I got your point.
Fixed on 1efc476

Signed-off-by: Yoshiki Fujikane <[email protected]>
@ffjlabo ffjlabo requested a review from Warashi March 3, 2025 06:50
Copy link
Contributor

@Warashi Warashi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ffjlabo ffjlabo enabled auto-merge (squash) March 3, 2025 06:56
@ffjlabo ffjlabo merged commit ce438ce into master Mar 3, 2025
17 of 18 checks passed
@ffjlabo ffjlabo deleted the extract-deploy-targets-in-sdk branch March 3, 2025 07:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants